#include"Service.h"

CTCPServer *g_pMyTcpServer;

/********************************
º¯  Êý£º
¹¦  ÄÜ£º
²Î  Êý£º

·µ»ØÖµ£º
Ëµ  Ã÷£º
********************************/
void ServiceInit()
{
	g_pMyTcpServer = new CTCPServer(5000);              //ÉèÖÃ¶Ë¿ÚºÅ²¢³õÊ¼»¯
	g_pMyTcpServer->m_setMessageSolve(ConnectRUN);      //ÉèÖÃ´¦Àíº¯Êý
    printf("Server Init...\r\n");
}
/********************************
º¯  Êý£º
¹¦  ÄÜ£º
²Î  Êý£º

·µ»ØÖµ£º
Ëµ  Ã÷£º
********************************/
void ServiceStart()
{
   g_pMyTcpServer->m_server->start();                  //Æô¶¯
   printf("Server Start...\r\n");

   pthread_t Pid;
      if(pthread_create(&Pid,NULL,ThreadShowServerMessage,NULL))
      {
         LOG(ERROR) << "Creat thread faild";          //ÈÕÖ¾
         google::ShutdownGoogleLogging();          // Í£Ö¹GLog
      }

}


void *ThreadShowServerMessage(void* p)
{
  while(1)
  {
    usleep(2000*1000);
	int n = g_pMyTcpServer->m_getCurrentConnections();
	printf("Thread number now : %d\r\n" ,n);
  }
  return 0;
}
/********************************
º¯  Êý£º
¹¦  ÄÜ£º
²Î  Êý£º

·µ»ØÖµ£º
Ëµ  Ã÷£º
********************************/
void ServiceDestory()
{
 delete(g_pMyTcpServer);
}
